<?php
include_once 'includes/config.php';
include_once 'includes/functions.php';
require_once '../includes/objects.php';

session_start();

$nom_dest = $_GET['nom_destinatario'];
$asunto = $_GET['asunto'];
$contenido = $_GET['contenido'];
$usuario = unserialize($_SESSION['usuario']);
$id_name = $usuario->id;
if($nom_dest=="self"){
	$id_receptor=$id_name;
}else{
	$obtenerid = "SELECT id_user FROM usuarios where user='$nom_dest'";
	$id_r = mysql_query($obtenerid, $conexion);
	
	while ($ver = mysql_fetch_assoc($id_r)) {
		$id_receptor = $ver['id_user'];
	}
}

$datos = "INSERT INTO buzon (id_emisor,id_receptor,asunto,contenido,f_mensaje) VALUES ('$id_name','$id_receptor','$asunto','$contenido',NOW())";
$ar = mysql_query($datos, $conexion);

if ($ar) {
	echo "ok";
} else {
	echo "fail";
}


?>